#include"Test.h"
void login(TcpClient& client) {
    cout<<"请输入id: ";
    int id;
    cin>>id;
    cout<<"请输入密码: ";
    string password;
    cin>>password;
    client.send_login_request(id, password);
}

void logout(TcpClient& client) {
    cout<<"请输入id: ";
    int id;
    cin>>id;
    client.send_logout_request(id);
}

void create_user(TcpClient& client) {
    cout<<"请输入用户名: ";
    string name;
    cin>>name;
    cout<<"请输入密码: ";
    string password;
    cin>>password;
    int id = client.send_create_user_request(name, password);
    cout<<"创建成功，id为"<<id<<endl;
}

void get_chat_list(TcpClient& client) {
    cout<<"请输入id: ";
    int id;
    cin>>id;
    client.send_get_chat_list_request(id);
}

void join_chat(TcpClient& client) {
    cout<<"请输入id: ";
    int id;
    cin>>id;
    cout<<"请输入聊天id: ";
    string chat_id;
    cin>>chat_id;
    client.send_join_chat_request(id, chat_id);
}

void create_chat(TcpClient& client) {
    cout<<"请输入id: ";
    int id;
    cin>>id;
    cout<<"请输入聊天名称: ";
    string chat_name;
    cin>>chat_name;
    client.send_create_chat_request(id, chat_name);
}

void exit_chat(TcpClient& client) {
    cout<<"请输入id: ";
    int id;
    cin>>id;
    cout<<"请输入聊天id: ";
    string chat_id;
    cin>>chat_id;
    client.send_exit_chat_request(id, chat_id);
}

void delete_chat(TcpClient& client) {
    cout<<"请输入id: ";
    int id;
    cin>>id;
    cout<<"请输入聊天id: ";
    string chat_id;
    cin>>chat_id;
    client.send_del_chat_request(id, chat_id);
}

void get_chat_info(TcpClient& client) {
    cout<<"请输入聊天id: ";
    string chat_id;
    cin>>chat_id;
    cout<<"请输入用户id: ";
    int user_id;
    cin>>user_id;
    client.send_get_chat_info_request(user_id, chat_id);
}

void send_msg(TcpClient& client) {
    cout<<"请输入用户id: ";
    int user_id;
    cin>>user_id;
    cout<<"请输入聊天id: ";
    string chat_id;
    cin>>chat_id;
    cout<<"请输入消息: ";
    string msg;
    cin>>msg;
    client.send_send_msg_request(user_id, chat_id, msg);
}

void get_newer_msg(TcpClient& client) {
    cout<<"请输入用户id: ";
    int user_id;
    cin>>user_id;
    cout<<"请输入聊天id: ";
    string chat_id;
    cin>>chat_id;
    cout<<"请输入消息数量: ";
    int num_msg;
    cin>>num_msg;
    client.send_get_newer_msg_request(user_id, chat_id, num_msg);
}

void invite_user(TcpClient& client) {
    cout<<"请输入用户id: ";
    int user_id;
    cin>>user_id;
    cout<<"请输入聊天id: ";
    string chat_id;
    cin>>chat_id;
    cout<<"请输入邀请用户id: ";
    int invite_user_id;
    cin>>invite_user_id;
    client.send_invite_user_request(user_id, chat_id, invite_user_id);
}

void print_menu() {
        cout<<"请输入指令："<<endl;
        cout<<"0.退出\t";
        cout<<"1.登录\t";
        cout<<"2.创建用户"<<endl;
        cout<<"3.登出用户\t";
        cout<<"4.获取聊天列表\t";
        cout<<"5.加入聊天"<<endl;
        cout<<"6.创建聊天\t";
        cout<<"7.退出聊天\t";
        cout<<"8.删除聊天"<<endl;
        cout<<"9.获取聊天信息\t";
        cout<<"10.发送消息\t";
        cout<<"11.获取新消息"<<endl;;
        cout<<"12.邀请用户\t";
}

void    main_menu(TcpClient& client) {
    int x=1;
    while (x)
    {
        print_menu();
        cin>>x;
        switch (x)
        {
        case 1:
            login(client);
            break;
        case 2:
            create_user(client);
            break;
        case 3:
            logout(client);
            break;
        case 4:
            get_chat_list(client);
            break;
        case 5:
            join_chat(client);
            break;
        case 6:
            create_chat(client);
            break;
        case 7:
            exit_chat(client);
            break;
        case 8:
            delete_chat(client);
            break;
        case 9:
            get_chat_info(client);
            break;
        case 10:
            send_msg(client);
            break;
        case 11:
            get_newer_msg(client);
            break;
        case 12:
            invite_user(client);
            break;
        case 0:
            break;
        default:
            cout<<"输入错误"<<endl;
            break; 
    }
}}